home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0077_Add menu items to the System Menu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-11-24  |  1.7 KB  |  70 lines

  1.  
  2. unit Unit1;
  3.  
  4. interface
  5.  
  6. uses
  7.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  8.   Forms, Dialogs, Menus;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.      procedure winmsg(var msg:tmsg;var handled:boolean);
  17.      {This is what handles the messages}
  18.  
  19.      procedure DOWHATEVER;{procedure to do whatever}
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28. const ItemID=99;{the ID number for your menu item--can be anything}
  29.  
  30. procedure tform1.winmsg(var msg:tmsg;var handled:boolean);
  31. begin
  32.   if msg.message=wm_syscommand then{if the message is a system one...}
  33.    if msg.wparam = ItemID then DOWHATEVER;{then check if its parameter
  34.                                            is your Menu items ID,}
  35. end;
  36.  
  37. procedure TForm1.FormCreate(Sender: TObject);
  38. begin
  39.   application.onmessage:=winmsg;
  40.   {tell your app that 'winmsg' is the application message handler}
  41.  
  42.   AppendMenu(GetSystemMenu(form1.handle,false),mf_separator,0,'');
  43.   {Add a seperator bar to form1}
  44.   
  45. AppendMenu(GetSystemMenu(form1.handle,false),mf_byposition,ItemID,
  46.   '&New Item');
  47. {add your menu item to form1}
  48.  
  49.   
  50. AppendMenu(GetSystemMenu(application.handle,false),mf_separator,0,'');
  51. {Add a seperator bar to the application system menu(used when app 
  52.  is minimized)}
  53.   
  54. AppendMenu(GetSystemMenu(application.handle,false),mf_byposition,
  55. ItemID,'&New Item'
  56. {add your menu itemto the application system menu(used when app is 
  57.  minimized)}
  58.  
  59. {for more information on the AppendMenu and GetSystemMenu see online
  60.  help}
  61.  
  62. end;
  63.  
  64. procdure TForm2.DOWHATEVER;
  65. begin
  66.  {add whatever you want to this procedure}
  67. end;
  68.  
  69. end.
  70.